#include <iostream>
#include <string>
using namespace std;

int main()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	int num;
	int a, b;
	string str;
	while(n--)
	{
		cin >> num;
		switch(num)
		{
			case 1:
				cin >> str;
				s.append(str);
				cout << s << endl;
				break;
			case 2:
				cin >> a >> b;
				s = s.substr(a, b);
				cout << s << endl;
				break;
			case 3:
				cin >> a;
				cin >> str;
				s.insert(a, str);
				cout << s << endl;
				break;
			case 4:
				cin >> str;
				int res = s.find(str);
				if(res != string::npos)
					cout << res << endl;
				else
					cout << -1 << endl;
				break;
				break;
		}
	}
	return 0;
}
